home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
lcppb.zip
/
LCPP04.ZIP
/
COLUMN.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-03
|
1KB
|
51 lines
// column.cpp -- Extract a column from input lines
//#include <stream.hpp>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#define NEWLINE '\n'
main(int argc, char *argv[])
{
char c; // I/O character
int cstart, cend; // Start and end column numbers
int cpos = 0; // Column position on current line
/* -- Display instructions if 1 or 0 arguments entered */
if (argc < 3) {
cerr << "COLUMN v1.00 (c) 1991 by Tom Swan\n";
cerr << "To use: Enter column number and width\n";
cerr << "Example: dir | column 1 12\n";
exit(1);
}
/* -- Calculate starting and ending columns */
cstart = atoi(argv[1]);
cend = cstart + atoi(argv[2]) - 1;
if (cstart < 1) cstart = 1;
if (cend < cstart) cend = cstart;
/* -- Copy selected column from input lines to output */
while ((c = getchar()) != EOF) {
cpos++;
if (c == NEWLINE) {
cout << NEWLINE;
cpos = 0;
} else if ((cstart <= cpos) && (cpos <= cend))
putchar(c);
}
}
// Copyright (c) 1990 by Tom Swan. All rights reserved
// Revision 1.00 Date: 08/02/1990 Time: 09:24 pm
// Revision 1.01 Date: 07/03/1991 Time: 04:00 pm
// Converted for Borland C++ 2.0